<template>
  <div class="search-box page" ref="webview">
    <div class="mall-search bg_grey">
      <div class="search">
        <van-field v-model="searchValue" class="input" ref="search" :clearable='true' placeholder="搜索商品/店铺">
          <template #right-icon>
            <i class="icon-search none"></i>
          </template>
        </van-field>
      </div>
      <div class="cancel" @click="$router.go(-1)">取消</div>
    </div>
    <div class="content">
      <div class="title">
        <span class="name">搜索记录</span>
        <span class="icon icon-del"></span>
      </div>
      <div class="list">
        <template v-for="item in historyList">
          <span class="name" @click="goSearch(item.key_word)" :key="item.id">{{item.key_word}}</span>
        </template>

        <!-- <span class="name">信封女包</span>
        <span class="name">连衣裙</span>
        <span class="name">吹发风机</span>
        <span class="name">信封女包</span>
        <span class="name">米家</span> -->
      </div>
    </div>
  </div>
</template>
<script>
export default {
  name: 'search',
  data () {
    return {
      searchValue: '',
      historyList: []
    };
  },
  created () { },
  mounted () {
    this.$nextTick(() => {
      this.$refs.search.focus();
    });
    this.getHistory();
  },
  methods: {
    // 跳转搜索
    goSearch (val) {
      this.$router.push({ path: '/mall/list', query: { searchValue: val } });
    },
    getHistory () {
      this.$API.user.getHistory().then(res => {
        if (!res.code) {
          this.historyList = res.data;
        }
      });
    }
  }
};
</script>
<style scoped lang="less">
.search-box {
  background-color: #fff;
  .mall-search {
    padding: 0 0 0 30px;
    .search {
      padding-right: 0;
    }
  }
  .cancel {
    color: #666;
    font-size: 32px;
    display: flex;
    padding: 0 30px;
    text-align: center;
    align-items: center;
  }
  .content {
    padding: 20px;
    .title {
      display: flex;
      padding: 10px 13px;
      justify-content: space-between;
      .name {
        font-size: 38px;
        font-weight: 800;
        color: #353535;
      }
      .icon {
        display: block;
        width: 28px;
        height: 30px;
        margin-top: 10px;
        margin-right: 12px;
        background-image: url('/static/img/icon-del.png');
        background-repeat: no-repeat;
        background-size: contain;
      }
    }
    .list {
      padding: 40px 5px;
      .name {
        display: inline-block;
        padding: 0 30px;
        background-color: #f2f4f5;
        line-height: 60px;
        border-radius: 60px;
        font-size: 28px;
        color: #666;
        margin: 0 16px 20px 0;
      }
    }
  }
}
</style>
